//
//  ViewController.m
//  Core Graphics Code
//
//  Created by liboxiang on 2019/1/10.
//  Copyright © 2019 liboxiang. All rights reserved.
//

#import "ViewController.h"
#import "DrawRectViewController.h"
#import "PathViewController.h"
#import "MutablePathRefController.h"
#import "ClipViewController.h"
#import "PatternViewController.h"
#import "ShadowViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) UITableView *tableView;

@property (strong, nonatomic) NSArray *titleArray;
@property (strong, nonatomic) NSArray *controllerNameArray;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self initData];
    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableFooterView = [UIView new];
    _tableView.rowHeight = 40;
    self.view = _tableView;
}

- (void)initData {
    _titleArray = @[@"Use Core Graphics in drawRect：",@"路径 Path",@"可变路径对象 CGMutablePathRef",@"裁剪路径",@"模式(Pattern)",@"阴影",@"透明层",@"位图和图像遮罩"];
    _controllerNameArray = @[@"DrawRectViewController",@"PathViewController",@"MutablePathRefController",@"ClipViewController",@"PatternViewController",@"ShadowViewController",@"TransparencyLayersController",@"BitMapAndMaskController"];
}

#pragma mark - UITableViewDelegate,UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _titleArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([UITableViewCell class])];
    }
    cell.textLabel.text = _titleArray[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *controllerName = _controllerNameArray[indexPath.row];
    Class controllerClass = NSClassFromString(controllerName);
    [self.navigationController pushViewController:[controllerClass new] animated:YES];
}

@end
